﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:System_Windows_Controls_DataVisualization_Charting_Primitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="StockTraderRI.Modules.Position.PositionSummary.PositionPieChartView"
    Height="170">
    <UserControl.Resources>
        <!-- By convention every view inside the ResearchControl (ResearchRegion) has to declare 
             a DataTemplate with the "HeaderIcon" key which defines the icon on the Header -->
        <DataTemplate x:Key="HeaderIcon">
            <Grid Margin="15,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="15.031" Height="15.055">
                <Ellipse Margin="0,0,0.031,0.055" Fill="{x:Null}" Stroke="#FFFFFFFF" StrokeThickness="2"/>
                <Path Margin="6.531,6.43,0,0" Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M66.625,440 L60.125,440 60.125,446.625"/>
            </Grid>
        </DataTemplate>

        <Style x:Key="ProportionsPieChart" TargetType="charting:PieSeries">
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:PieSeries">
                        <Canvas x:Name="PlotArea"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style x:Key="ProportionsChartContainer" TargetType="charting:Chart">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="IsTabStop" Value="False"/>
          
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:Chart">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>

                                <datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" />

                                <!-- Use a nested Grid to avoid possible clipping behavior resulting from ColumnSpan+Width=Auto -->
                                <Grid Grid.Row="1" Margin="0,15,0,15" RenderTransformOrigin="0.5,0.5">
                                	<Grid.RenderTransform>
                                		<CompositeTransform TranslateY="-40"/>
                                	</Grid.RenderTransform>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <datavis:Legend x:Name="Legend" Header="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}" Grid.Column="1" Background="{x:Null}" BorderBrush="{x:Null}" d:IsLocked="True" />
                                    <System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel 
                                            x:Name="ChartArea" 
                                            Style="{TemplateBinding ChartAreaStyle}" RenderTransformOrigin="0.5,0.5"                                            
                                        >
                                    	<System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel.RenderTransform>
                                    		<CompositeTransform/>
                                    	</System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel.RenderTransform>
                                        <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" Background="{x:Null}" />
                                        <Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" Visibility="Collapsed" />
                                    </System_Windows_Controls_DataVisualization_Charting_Primitives:EdgePanel>
                                </Grid>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    	
    </UserControl.Resources>
    <Border BorderThickness="0,0,0,1" BorderBrush="#FFFFFFFF" Padding="10,10,10,10">
    <StackPanel>
		<TextBlock Text="PIE CHART" Style="{StaticResource TextBlockSectionTitle}" AutomationProperties.AutomationId="PieChartTextBlock" />
            <charting:Chart Style="{StaticResource ProportionsChartContainer}" BorderBrush="{x:Null}" Height="Auto" Width="Auto">
            	<charting:PieSeries ItemsSource="{Binding Position.Items}" 
            		IndependentValueBinding="{Binding TickerSymbol}"
            		DependentValueBinding="{Binding MarketValue}"
            		Margin="0,0,0,0" Width="Auto" Height="Auto" />
            </charting:Chart>
        </StackPanel>
    </Border>
</UserControl>
